<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Util extends BaseController {
    public function __construct() {
        parent::__construct();

        $this->load->library('ffmpeg');
    }

    // // 截取视频封面
    // public function video_snapshot() {
    //     $videoLink = $this->get('video_link');
    //     // 加载又拍云sdk
    //     require_once('vendor/autoload.php');
    //     // 初始化又拍云接口
    //     $config = new Upyun\Config(UP_BUCKET, UP_USERNAME, UP_PASSWORD);
    //     $upyun = new Upyun\Upyun($config);
    //     $videoUrl = str_replace(UP_URL, '', $videoLink);
    //     $videoCover = date("Y") . "/" . date("m") . "/" . date("d"). "/". uniqid() . '.jpg';
    //     $result = $upyun->snapshot($videoUrl, $videoCover, '00:00:01');
    //     $videoCover = UP_URL . $result['save_as'];
    //     exit(json('', true, array(
    //         'video_cover' => $videoCover
    //     )));
    // }
    // public function video_compress(){
    //     $source = $this->get('source');
    //     $saveAs = $this->get('save_as');
    //     // 加载又拍云sdk
    //     require_once('vendor/autoload.php');
    //     // 初始化又拍云接口
    //     $config = new Upyun\Config(UP_BUCKET, UP_USERNAME, UP_PASSWORD);
    //     $upyun = new Upyun\Upyun($config);
    //     $upyun->compress($source, $saveAs);
    //     // $ret = $upyun->compress($source, $saveAs);
    //     // var_export($ret);exit;
        
    // }

    // 截取视频封面
    public function video_snapshot() {
        $videoLink = $this->get('video_link');
     
        $videoCover = $this->ffmpeg->snapshot($videoLink);
        exit(json('', true, array(
            'video_cover' => $videoCover
        )));
    }
    public function video_compress(){

        $source = $this->get('source');
        $saveAsLink = $this->get('save_as_link');
        // $name = $this->get('name');
        // $size = $this->get('size');
        // // 原视频如果为mp4且小于200m，不需转码，返回原路径
        // if(strstr($name, '.mp4') && $size < 1024 * 1024 * 200) {
        //     exit(json('', true, array(
        //         'url_compress' => $source
        //     )));
        // }

        $this->ffmpeg->compress($source, $saveAsLink);
        exit(json('', true));
        // echo 'bb';exit;
    }

}